package com.cola.springmvc.converter;

import org.springframework.core.convert.converter.Converter;

import javax.xml.transform.Source;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Grup:com.cola.springmvc.converter
 * @Auther:cola
 * @Data:2021/5/1-2021-05-17:50
 * @version:1.0
 */
public class DateConverter implements Converter<String, Date> {
    /*
    * 将字符串转换为日期格式
    * */
    @Override
    public Date convert(String source) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        try {
            sdf.setLenient(false);//是宽松解析:默true
            return sdf.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
